package com.gopay.common.cps.dao.fund.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.fund.FundDifferFileNotifyDAO;
import com.gopay.common.domain.fund.FundGopayReconFinishNotifyEntity;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BindCardDAOImpl.java
 * @author baiyunpeng
 * @2016年7月4日 上午10:27:00  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("fundDifferFileNotifyDAO")
public class FundDifferFileNotifyDAOImpl extends BaseDAOImpl<FundGopayReconFinishNotifyEntity,Serializable> implements FundDifferFileNotifyDAO {
    /**
     * 更新差异文件状态
      * @param map
     */
    @Override
    public Integer updateFundDifferFile(Map<String, Object> map) {

        //业务日期
        Date reconciliationDate = (Date) map.get("reconciliationDate");

        //银行产生的流水
        String serialNo = (String) map.get("serialNo");


        //文件对账状态
        String status = (String) map.get("status");

        //对账完成时间
        Date reconciliationFinishTime = (Date) map.get("reconciliationFinishTime");


        //第三方处理结果是否成功
        String isSucc = (String) map.get("isSucc");


        //处理完成时间
        Date depositTime = (Date) map.get("depositTime");

        //最后更新时间
        Date lastUpdTs = (Date) map.get("lastUpdTs");


        StringBuffer sql = new StringBuffer(" Update FUND_GOPAY_RECON_FINISH_NOTIFY t set t.RECONCILIATION_FINISH_TIME=:reconciliationFinishTime" +
        ", t.IS_SUCC=:isSucc ,t.DEPOSIT_TIME=:depositTime, t.LAST_UPD_TS=:lastUpdTs WHERE t.SERIAL_NO=:serialNo AND t.RECONCILIATION_DATE=:reconciliationDate");

        Map<String,Object> maps = new HashMap<>();
        maps.put("reconciliationFinishTime",reconciliationFinishTime);
        maps.put("isSucc",isSucc);
        maps.put("depositTime",depositTime);
        maps.put("lastUpdTs",lastUpdTs);
        maps.put("serialNo",serialNo);
        maps.put("reconciliationDate",reconciliationDate);
        int i = updateBySql(sql.toString(), maps);
        return i;
    }
    @Override
    public List<FundGopayReconFinishNotifyEntity> getIsReconFinish(String fileName){
        StringBuffer sql = new StringBuffer("");
        if(fileName!=null) {
            sql.append(" from FundGopayReconFinishNotifyEntity where differenceFileName like :fileName");
            Map<String,Object> map = new HashMap<>();
            map.put("fileName",fileName);
            List<FundGopayReconFinishNotifyEntity> byHql = findByHql(sql.toString(), map);
            return byHql;
        }
        return null;
    }

}
